###
# Button: 按钮
###

import tkinter as tk
import tkinter.ttk as ttk

class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.count = 0
        self.show_label_text = False
    
    def load_basic_config(self):
        self.title('My Label')
        self.geometry(f'960x720')
        self.configure(background='white')
        self.resizable(False, False)
    
    def run(self):
        self.label = tk.Label(self, background='white')
        self.label.pack()
        self.button = tk.Button(self, text='点击我', command=self.click_call_back)  
        self.button.pack()

        # self.label.forget()

        # self.button_clear = tk.Button(self, text='Clear', command=self.clear, background='lightgray')
        # self.button_clear.pack(anchor='s', side='left', padx=5)
        # self.button_yellow = tk.Button(self, text='Yellow', command=self.show_yellow, background='lightgray')
        # self.button_yellow.pack(anchor='s', side='left', padx=5)
        # self.button_black = tk.Button(self, text='Black', command=self.show_black, background='lightgray')
        # self.button_black.pack(anchor='s', side='left', padx=5)

        # 使用lambda
        self.button_clear = tk.Button(self, text='Clear', command=lambda:self.change_background('white'), background='lightgray')
        self.button_clear.pack(anchor='s', side='left', padx=5)
        self.button_yellow = tk.Button(self, text='Yellow', command=lambda:self.change_background('yellow'), background='lightgray')
        self.button_yellow.pack(anchor='s', side='left', padx=5)
        self.button_black = tk.Button(self, text='Black', command=lambda:self.change_background('black'), background='lightgray')
        self.button_black.pack(anchor='s', side='left', padx=5)

    def click_call_back(self):
        if not self.show_label_text:
            self.show_label_text = True
            self.label.configure(text="Hello World!", background='lightyellow', foreground='red')
        else:
            self.show_label_text = False
            bg = self.config('background')
            self.label.configure(text="", background=str(bg[4]), foreground=str(bg[4]))

    
    def show_yellow(self):
        self.configure(background='yellow')
    
    def show_black(self):
        self.configure(background='black')

    def clear(self):
        self.configure(background='white')
    
    def change_background(self, bg_color):
        self.label.configure(background=bg_color, foreground=bg_color) # 背景颜色变换时，文本也继续隐藏
        self.configure(background = bg_color)
        

if __name__ == '__main__':
    app = App()
    app.load_basic_config()

    app.run()

    app.mainloop()